package com.own.demo.jts;

import com.alibaba.fastjson.JSONArray;
import com.own.demo.utils.DateUtils;
import com.own.demo.utils.FileToStringUtils;
import com.own.demo.utils.RegionUtil;
import com.own.demo.utils.geo.buffer.BufferBase;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;

import java.io.File;

public class Distance {
    public static void main(String[] args) {
        File geoZJ = new File("E:\\ownCode\\emg-geojson - 副本\\src\\test\\java\\com\\own\\demo\\jts\\point");
        String geoData = FileToStringUtils.txt2String(geoZJ);
        JSONArray jsonArray=JSONArray.parseArray(geoData);
        JSONArray jsonArrayOne=jsonArray.getJSONArray(0);
        int row=jsonArray.size();

        for(int i=1;i<row;i++){
            Coordinate coordinateStart= new Coordinate(jsonArrayOne.getDouble(0),jsonArrayOne.getDouble(1));
            JSONArray jsonArrayEnd=jsonArray.getJSONArray(i);
            Coordinate coordinateEnd= new Coordinate(jsonArrayEnd.getDouble(0),jsonArrayEnd.getDouble(1));
            Point p1= BufferBase.geometryFactory.createPoint(coordinateStart);
            Point p2= BufferBase.geometryFactory.createPoint(coordinateEnd);
            double dist= RegionUtil.distance(coordinateStart.x,coordinateStart.y,coordinateEnd.x,coordinateEnd.y);
            System.out.println(DateUtils.getNewDateSs()+" 距离："+p1.distance(p2) +"  "+dist);
            jsonArrayOne=jsonArrayEnd;
        }
    }
}
